#ifndef PIDREGULATOR_H
#define PIDREGULATOR_H

#include "pidregulatorconfig.h"

class PidRegulator {
public:
	PidRegulator();
	~PidRegulator();
	
	// configure and reset the regulator
	void setConfig(const PidRegulatorConfig &config);

	// change output limits without reset
	void setMinMax(float min, float max);
	void setMinMax(float lim);
	float getMin() const;
	float getMax() const;
	
	// change kP, kD scale
	void setScale(float scale);
	
	// reset (or track) the regulator
	void reset(float output = 0);

	// calculate output
	float operator()(float reference, float feedback);	
	
	// calculate output with measured feedback derivative
	float operator()(float reference, float feedback, float d_feedback);	

	// get cached output
	float getOutput() const;
	
private:
	PidRegulatorConfig config_;
	float integrator_;
	float satError_;
	float prev_feedback_;
	float output_;
	float scale_;
};



#endif


